<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-5-24
 * Time: 上午11:21
 */

namespace ActionsHttp;

use Config\ConstArray;
use Data\Food_DAO;
use Data\Order_form;

class ConsumerOrderNew extends BaseActionHttp
{
    public function doAction() {
        parent::doAction();
        // 顾客id
        $consumer_id = $_SESSION[CONSUMER_ID];
        // 餐馆id
        $restaurant_id = (int)$this->data[RESTAURANT_ID];
        // 桌号
        $table_number = $this->data[TABLE_NUM];
        // 是否外带
        $is_take_out  = (int)$this->data[IS_TAKE_OUT];
        // 详细订单
        $order_for_food = $this->data[ORDER_FOR_FOOD];


        // 生成订单
        $order_form_record = new Order_form(array());


        if (!array_key_exists($is_take_out,array(STATE_YES,STATE_NO))) {
            return $this->SendErrMsg("参数错误，请选择外带或是在餐厅内食用");
        }
        // 是否外带
        if ($is_take_out == STATE_NO) {
            // 不外带（在餐馆用餐）
            // 用餐人数
            $consumer_count = $this->data[CONSUMER_COUNT];

            foreach ($order_for_food as $food_id=>$food_count) {
                // 商品记录
                $food_record = Food_DAO::getRecordByIdResId($food_id,$restaurant_id);
                if (!$food_record) {
                    return $this->SendErrMsg("参数错误，有商品不存在");
                }
                // 商品存在
                // 商品是否限量
                $food_is_limit = $food_record->getIS_LIMIT();
                if ($food_is_limit == STATE_YES) {
                    // 商品限量
                    // 商品剩余量
                    $stock_left =  $food_record->getSTOCK_LEFT();
                    if ($food_count>$stock_left) {
                        return $this->SendErrMsg("参数错误，有商品库存不足");
                    }
                }

                // 商品单价
                $food_price =

                $order_for_foods_list = array($food_id=>array($food_count,));

            }













        } elseif ($is_take_out == STATE_YES) {
            // 外带

        }




    }
}